1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.Module;
26 
27 private import glib.ErrorG;
28 private import glib.GException;
29 private import glib.Str;
30 private import glib.c.functions;
31 public  import glib.c.types;
32 
33 
34 /**
35  * The #GModule struct is an opaque data structure to represent a
36  * [dynamically-loaded module][glib-Dynamic-Loading-of-Modules].
37  * It should only be accessed via the following functions.
38  */
39 public class Module
40 {
41 	/** the main Gtk struct */
42 	protected GModule* gModule;
43 	protected bool ownedRef;
44 
45 	/** Get the main Gtk struct */
46 	public GModule* getModuleStruct(bool transferOwnership = false)
47 	{
48 		if (transferOwnership)
49 			ownedRef = false;
50 		return gModule;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected void* getStruct()
55 	{
56 		return cast(void*)gModule;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (GModule* gModule, bool ownedRef = false)
63 	{
64 		this.gModule = gModule;
65 		this.ownedRef = ownedRef;
66 	}
67 
68 
69 	/**
70 	 * Closes a module.
71 	 *
72 	 * Returns: %TRUE on success
73 	 */
74 	public bool close()
75 	{
76 		return g_module_close(gModule) != 0;
77 	}
78 
79 	/**
80 	 * Ensures that a module will never be unloaded.
81 	 * Any future g_module_close() calls on the module will be ignored.
82 	 */
83 	public void makeResident()
84 	{
85 		g_module_make_resident(gModule);
86 	}
87 
88 	/**
89 	 * Returns the filename that the module was opened with.
90 	 *
91 	 * If @module refers to the application itself, "main" is returned.
92 	 *
93 	 * Returns: the filename of the module
94 	 */
95 	public string name()
96 	{
97 		return Str.toString(g_module_name(gModule));
98 	}
99 
100 	/**
101 	 * Gets a symbol pointer from a module, such as one exported
102 	 * by %G_MODULE_EXPORT. Note that a valid symbol can be %NULL.
103 	 *
104 	 * Params:
105 	 *     symbolName = the name of the symbol to find
106 	 *     symbol = returns the pointer to the symbol value
107 	 *
108 	 * Returns: %TRUE on success
109 	 */
110 	public bool symbol(string symbolName, void** symbol)
111 	{
112 		return g_module_symbol(gModule, Str.toStringz(symbolName), symbol) != 0;
113 	}
114 
115 	/**
116 	 * A portable way to build the filename of a module. The platform-specific
117 	 * prefix and suffix are added to the filename, if needed, and the result
118 	 * is added to the directory, using the correct separator character.
119 	 *
120 	 * The directory should specify the directory where the module can be found.
121 	 * It can be %NULL or an empty string to indicate that the module is in a
122 	 * standard platform-specific directory, though this is not recommended
123 	 * since the wrong module may be found.
124 	 *
125 	 * For example, calling g_module_build_path() on a Linux system with a
126 	 * @directory of `/lib` and a @module_name of "mylibrary" will return
127 	 * `/lib/libmylibrary.so`. On a Windows system, using `\Windows` as the
128 	 * directory it will return `\Windows\mylibrary.dll`.
129 	 *
130 	 * Params:
131 	 *     directory = the directory where the module is. This can be
132 	 *         %NULL or the empty string to indicate that the standard platform-specific
133 	 *         directories will be used, though that is not recommended
134 	 *     moduleName = the name of the module
135 	 *
136 	 * Returns: the complete path of the module, including the standard library
137 	 *     prefix and suffix. This should be freed when no longer needed
138 	 */
139 	public static string buildPath(string directory, string moduleName)
140 	{
141 		auto retStr = g_module_build_path(Str.toStringz(directory), Str.toStringz(moduleName));
142 
143 		scope(exit) Str.freeString(retStr);
144 		return Str.toString(retStr);
145 	}
146 
147 	/**
148 	 * Gets a string describing the last module error.
149 	 *
150 	 * Returns: a string describing the last module error
151 	 */
152 	public static string error()
153 	{
154 		return Str.toString(g_module_error());
155 	}
156 
157 	/** */
158 	public static GQuark errorQuark()
159 	{
160 		return g_module_error_quark();
161 	}
162 
163 	/**
164 	 * A thin wrapper function around g_module_open_full()
165 	 *
166 	 * Params:
167 	 *     fileName = the name of the file containing the module, or %NULL
168 	 *         to obtain a #GModule representing the main program itself
169 	 *     flags = the flags used for opening the module. This can be the
170 	 *         logical OR of any of the #GModuleFlags.
171 	 *
172 	 * Returns: a #GModule on success, or %NULL on failure
173 	 */
174 	public static Module open(string fileName, GModuleFlags flags)
175 	{
176 		auto __p = g_module_open(Str.toStringz(fileName), flags);
177 
178 		if(__p is null)
179 		{
180 			return null;
181 		}
182 
183 		return new Module(cast(GModule*) __p);
184 	}
185 
186 	/**
187 	 * Opens a module. If the module has already been opened,
188 	 * its reference count is incremented.
189 	 *
190 	 * First of all g_module_open_full() tries to open @file_name as a module.
191 	 * If that fails and @file_name has the ".la"-suffix (and is a libtool
192 	 * archive) it tries to open the corresponding module. If that fails
193 	 * and it doesn't have the proper module suffix for the platform
194 	 * (%G_MODULE_SUFFIX), this suffix will be appended and the corresponding
195 	 * module will be opened. If that fails and @file_name doesn't have the
196 	 * ".la"-suffix, this suffix is appended and g_module_open_full() tries to open
197 	 * the corresponding module. If eventually that fails as well, %NULL is
198 	 * returned.
199 	 *
200 	 * Params:
201 	 *     fileName = the name of the file containing the module, or %NULL
202 	 *         to obtain a #GModule representing the main program itself
203 	 *     flags = the flags used for opening the module. This can be the
204 	 *         logical OR of any of the #GModuleFlags
205 	 *
206 	 * Returns: a #GModule on success, or %NULL on failure
207 	 *
208 	 * Since: 2.70
209 	 *
210 	 * Throws: GException on failure.
211 	 */
212 	public static Module openFull(string fileName, GModuleFlags flags)
213 	{
214 		GError* err = null;
215 
216 		auto __p = g_module_open_full(Str.toStringz(fileName), flags, &err);
217 
218 		if (err !is null)
219 		{
220 			throw new GException( new ErrorG(err) );
221 		}
222 
223 		if(__p is null)
224 		{
225 			return null;
226 		}
227 
228 		return new Module(cast(GModule*) __p);
229 	}
230 
231 	/**
232 	 * Checks if modules are supported on the current platform.
233 	 *
234 	 * Returns: %TRUE if modules are supported
235 	 */
236 	public static bool supported()
237 	{
238 		return g_module_supported() != 0;
239 	}
240 }